package com.demo.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author WuLiangHang
 */
@WebServlet("/listener.do")
public class ListenerServlet extends BaseServlet {
    public String contextOperation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        context.setAttribute("a", "a");
        context.setAttribute("a", "A");
        context.removeAttribute("a");
        return "/index.jsp";
    }

    public String sessionOperation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        session.setAttribute("a", "a");
        session.setAttribute("a", "A");
        session.removeAttribute("a");
        return "/index.jsp";
    }

    public String requestOperation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("a", "a");
        req.setAttribute("a", "A");
        req.removeAttribute("a");
        return "/index.jsp";
    }
}
